# -*-coding:utf-8-*-
class ParseResult(object):
    def __init__(self, fenci_res, pos_res, ddp_res):
        self.fenci_res = fenci_res
        self.pos_res = pos_res
        self.ddp_res = ddp_res

    def get_hed_info(self):
        hed_num = -1  # hed在词表中的位置，从1算起
        for i in range(len(self.ddp_res[0]['word'])):
        # for i in range(len(self.fenci_res)):
            if self.ddp_res[0]["deprel"][i] == "HED":
                hed_num = i + 1
        hed_info = {"word": self.ddp_res[0]["word"][hed_num - 1], 'pos': self.pos_res[hed_num - 1], "num": hed_num,
                     "deprel": self.ddp_res[0]["deprel"][hed_num - 1]}  # 字典单独存储HED信息
        print('hed_info：', hed_info)
        return  hed_info

    def get_modifi_info(self):
        # SBV,VOB,POB,ADV,CMP,ATT,F,COO,DBL,DOB,VV,IC,MT
        sbv_info, vob_info, pob_info, adv_info, cmp_info, att_info, f_info, coo_info, dbl_info, dob_info, vv_info, ic_info, mt_info = [[] for lst in range(13)]
        deprel = self.ddp_res[0]['deprel']
        for i in range(len(self.pos_res)):
            if deprel[i] == 'SBV':
                sbv_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'VOB':
                vob_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'POB':
                pob_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'ADV':
                adv_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'CMP':
                cmp_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'ATT':
                att_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'F':
                f_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'COO':
                coo_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'DBL':
                dbl_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'DOB':
                dob_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'VV':
                vv_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'IC':
                ic_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})
            if deprel[i] == 'MT':
                mt_info.append({'word': self.ddp_res[0]['word'][i], 'pos': self.pos_res[i], 'deprel': self.ddp_res[0]['deprel'][i],
                                 'hed_word': self.ddp_res[0]['word'][(self.ddp_res[0]['head'][i]) - 1], 'num': i})

        parse_info = {'sbv_info':sbv_info, 'vob_info':vob_info, 'pob_info':pob_info,
                           'adv_info':adv_info, 'cmp_info':cmp_info, 'att_info':att_info,
                           'f_info':f_info, 'coo_info':coo_info, 'dbl_info':dbl_info,
                           'dob_info':dob_info, 'vv_info':vv_info, 'ic_info':ic_info, 'mt_info':mt_info,
                            'dep_rel':deprel}        # 字典存储所有句法分析结果

        return parse_info

